'''
Created on Jan 22, 2013

@author: Artur
'''
import math
from matplotlib import pyplot as plt
import numpy as np
from scipy.special import binom

interval = .05
p = .25

x = []
y = []

for n in range(1, 1000):
    low = math.ceil(n * (p - interval))
    high = math.floor(n * (p + interval))
    prob = 0.0
    for i in range(low, high + 1):
        prob += binom(n, i) * p ** i * (1 - p) ** (n-i)
                
    x.append(n)
    y.append(prob)
    

plt.plot(x, y, '-r')


interval = .05
p = .5

x = []
y = []

for n in range(1, 1000):
    low = math.ceil(n * (p - interval))
    high = math.floor(n * (p + interval))
    prob = 0.0
    for i in range(low, high + 1):
        prob += binom(n, i) * p ** i * (1 - p) ** (n-i)
                
    x.append(n)
    y.append(prob)
    

plt.plot(x, y, '-g')

plt.show()